package com.ls.netty.inboundoutboundhandler.server;

import com.ls.netty.inboundoutboundhandler.coder.MyByteToLongDecoder;
import com.ls.netty.inboundoutboundhandler.coder.MyByteToLongDecoder2;
import com.ls.netty.inboundoutboundhandler.coder.MyLongToByteEncoder;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

public class MyServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        //入站解码 MyByteToLongDecoder
        pipeline.addLast(new MyByteToLongDecoder2());
//        pipeline.addLast(new MyByteToLongDecoder());
        pipeline.addLast(new MyLongToByteEncoder());
        pipeline.addLast(new MyServerHandler());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
